﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace DragDraw
{
    public partial class ColorBoard : UserControl
    {
        public Color CurrentColor
        {
            get { return color; }
            set
            {
                color = value;
                refresh();
            }
        }
        private Color color;
        private int i;
        public ColorBoard()
        {
            InitializeComponent();
            i = 0;
            color = new Color();
        }

        private void AlphaSlider_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
        {
            refresh();
        }

        private void RedSlider_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
        {
            refresh();
        }

        private void GreenSlider_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
        {
            refresh();
        }

        private void BlueSlider_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
        {
            refresh();
        }
        private void refresh()
        {
            if (i >= 4)//估计是因为其他的东西还没有初始化的问题
            {
                color = Color.FromArgb((byte)AlphaSlider.Value, (byte)RedSlider.Value, (byte)GreenSlider.Value, (byte)BlueSlider.Value);
                PreviewColor.Fill = new SolidColorBrush(color);
                HexColor.Text = color.ToString();
                return;
            }
            i++;
        }
    }
}
